import request from '@/utils/request.js'
import { setToken } from '@/utils/storage'

/**
 * 
 * @param {*} mobile 
 * @returns 
 */
export const getCode = (mobile) => {
    return async dispatch => {
        await request.get(`/sms/codes/${mobile}`)
    }
}


/**
 * 存放token
 * @param {*} payload 
 * @returns 
 */
export const saveToken = (payload) => {
    return {
        type: 'login/token',
        payload
    }
}

/**
 * 登陆接口处理
 * @param {*} data 
 * @returns 
 */
export const login = (data) => {
    return async dispatch => {
        const res = await request.post(`/authorizations`, data)
        //存放token到redux
        dispatch(saveToken(res.data))
        // 存放token到localStorage中
        setToken(res.data)
    }
}




